package com.tegtech.starter.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.lang3.ArrayUtils;

import com.tegtech.starter.validator.annotation.Contain;

/**
 * Contain注解校验实现类
 * @Author Jun
 * @date 2020年5月2日 下午2:10:49
 */
public class ContainValidator implements ConstraintValidator<Contain, Integer> {

	private int[] values = {};
	
	@Override
    public void initialize(Contain constraintAnnotation) {
		values = constraintAnnotation.values();
    }
	

	@Override
	public boolean isValid(Integer value, ConstraintValidatorContext context) {
		if(values == null || values.length == 0 || value == null) {
			return false;
		}
		return ArrayUtils.contains(values, value);
	}

}
